import React, { Component } from 'react'
import store from '../../redux/store'
export default class Count extends Component {
    // store.getState() 获取store的状态
    // store.dispatch 通知 派遣
    // store.subscribe 监听store状态变化

    componentDidMount() {
        // 监测redux中状态变化，只要变化，就调用render
        store.subscribe(() => {
            this.setState({})
        })

    }

    increment = () => {
        const { value } = this.selectNumber
        //  通知redux加value
        store.dispatch({ type: 'increment', data: parseInt(value) })
    }
    render() {
        return (
            <div>
                <h1>当前求和为：{store.getState()}</h1>
                <select ref={c => this.selectNumber = c}>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>&nbsp;
                <button onClick={this.increment}>加加</button>
            </div>
        )
    }
}
